//
//  UIButton+Block.m
//  TravelGuideMdd
//
//  Created by 陈曦 on 14/10/30.
//  Copyright (c) 2014年 mafengwo.com. All rights reserved.
//

#import "UIButton+Block.h"

@implementation UIButton(Block)
static const char UIButton_Block_Key;
- (void)setYuWeiOnClick:(void (^)(UIButton *))yuWeiOnClick
{
    NSInteger flag = 0;
    if(self.yuWeiOnClick)
    {
        flag -= 1;
        
    }
    if (yuWeiOnClick)
    {
        
        flag += 1;
    }
    [self setCopyNonatomicProperty:yuWeiOnClick byKey:&UIButton_Block_Key];
    
    switch (flag) {
        case -1:
            [self removeTarget:self
                        action:@selector(yuwei_UIButton_On_Click)
              forControlEvents:UIControlEventTouchUpInside];
            break;
        case 0:
            break;
        case 1:
        default:
            [self addTarget:self
                     action:@selector(yuwei_UIButton_On_Click)
           forControlEvents:UIControlEventTouchUpInside];
            break;
    }
    
}

- (void(^)(UIButton*))yuWeiOnClick
{
    return [self getAssociativeValue:&UIButton_Block_Key];
}

- (void)yuwei_UIButton_On_Click
{
    if (self.yuWeiOnClick)
    {
        self.yuWeiOnClick(self);
    }
}

@end





